package com.dumovie.utils;


import java.util.HashMap;
import java.util.Map;

import org.hibernate.boot.model.naming.IllegalIdentifierException;

public class MapUtils {
	public static Map<String, Object> of(Object... val) {
		if (val == null)
			return null;
		Map<String, Object> m = new HashMap<String, Object>();
		if (val.length % 2 == 1) {
			throw new IllegalIdentifierException("key & values must be pair values");
		}
		for (int i = 0; i < val.length; i++) {
			if (i % 2 == 1) {
				if (val[i - 1] == null)
					throw new IllegalIdentifierException("key nust not be null");
				m.put(val[i - 1].toString(), val[i]);
			}
		}
		return m;
	}
	
	public static <K, V> Map<K, V> of(K[] k, V[] v) {
		if(k==null||v==null||k.length==0||v.length==0)return null;
		Map<K,V> m = new HashMap<K,V>();
		for (int i = 0; i < k.length; i++) {
			m.put(k[i], v[i]);
		}
		return m;
	}
	
	public static Map<String, Map<String,Object>> conditionMap(Object... val) {
		if (val == null)
			return null;
		Map<String, Map<String,Object>>m = new HashMap<String, Map<String,Object>>();
		if (val.length % 2 == 1) {
			throw new IllegalIdentifierException("key & values must be pair values");
		}
		for (int i = 0; i < val.length; i++) {
			if (i % 2 == 1) {
				if (val[i - 1] == null)
					throw new IllegalIdentifierException("key nust not be null");
				try{
					m.put(val[i - 1].toString(), (Map<String, Object>) val[i]);
				}catch(Exception e){
					e.printStackTrace();
					throw e;
				}
			}
		}
		return m;
	}
}
